﻿#pragma once

#include<QObject>
#include<QTimer>
#include<opencv2\opencv.hpp>
#include<memory>
#include <QMap>
#include "include\Interfaces\BinocularCamera.h"
#include "include\Widget\CameraWidget.h"

#include <QtCharts/QChartView>
#include<QtCharts/QValueAxis>

#include <qelapsedtimer.h>

QT_CHARTS_USE_NAMESPACE

class Imageloader;

class DisplayThread :public QObject {

	Q_OBJECT
public:
	//DisplayThread(std::shared_ptr<Imageloader> loader, CameraID id);
	DisplayThread(Imageloader* loader, CameraID id);

	~DisplayThread();

	void timeCount(cv::Mat &img);
signals:
	void stopCapture(QString text);

public slots:
	void startThread();
	void stopThread();
	void onSetParam(int type, double value);

	void onSaveCaptrue(QString path);
	void onSendParam(QString value, const int TIME);
	void onSendTime(const int eachTime, const int timeTotal);
	void onstopPhoto();
private:
	int openCamera();
	void closeCamera();

	void calHist(cv::Mat &img);
	void saveImage(cv::Mat &img);
protected slots:
	virtual void show() ;
signals:
	void updateParam(int type,double value);
	void updateCameraStatus(QString msg);

	void updateSeries(QPointF *data);
	void SetExposure(double value);

protected:
	//std::shared_ptr<Imageloader> _loader;
	Imageloader* _loader = nullptr;

	std::shared_ptr<BinocularCamera> _camera;			//智能指针
    int TIMER_INTERVAL = 50;							//设置初始刷新率是50ms
	std::shared_ptr<QTimer> _timer;						//智能指针，避免new指针，等价于QTimer *_timer = new QTimer()；
	CameraID _port;
	qint64 index = 0;

	QElapsedTimer _elapseTimer;
	QString _storePath;
	qint64 _timeCount = 0;
	bool _isStartCapture = false;
	int count = 0;

private:
	int _eachTime = 0;
	int _timeTotal = 0;
	QString v;

};
